<?php
session_start();
if(empty($_SESSION['user'])){
    echo "您还没登录，请先登录";
    $url='/index.php';
    echo "<a href='".$url."'>".'返回首页'."</a>";
    die();
}
?>


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>xxx图书管理系统</title>


    <!-- 可选的 Bootstrap 主题文件（一般不用引入） -->
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" >



    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" >

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style type="text/css">
        .imgheight{
            height: 50px;
        }

    </style>


</head>
<body>

<a href="index.php">返回首页</a><br>
<?php
try {
    $dsn = 'mysql:dbname=Library;host=127.0.0.1';
    $user = 'root';
    $password = '123456';
    $db = new PDO($dsn, $user, $password);
    $result=$db->query('select * from Book')->fetchAll();

} catch (PDOException $e) {
    var_dump($e->getMessage());
    die('程序出错');
}


?>



<table class="table table-condensed">
    <thead>
    <tr>
        <th>ID</th>
        <th>书名</th>
        <th>封面</th>
        <th>作者</th>
        <th>状态</th>
    </tr>
    </thead>
    <tbody>
    <?php
    foreach($result as $book){
        $url='/book.php?id='.$book['ID'];
        echo '<tr class= "info">';
        echo '<th scope="row">'."<a href='".$url."'>". $book['ID'].'</a>'.'</th>';
        echo "<td>"."<a href='".$url."'>". $book['Name'].'</a>'."</td>";
        echo "<td>"."<img class='imgheight' src='".$book['BookImg']."'>"."</td>";
        echo "<td>"."<a href='".$url."'>". $book['Author'].'</a>'."</td>";
        if($book['Status']=='1')
            echo "<td>".'在库'."</td>";
        else
            echo "<td>".'借出'."</td>";
    }
    ?>

    </tbody>
</table>

<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>
